package main;

import java.lang.reflect.Field;
import org.jboss.aop.joinpoint.FieldWriteInvocation;;

public class ObserverAspect {

	/**
	 * @param args
	 */
	public Object fieldChanged(FieldWriteInvocation invocation) throws Throwable {
		try {

			 Observable target = (Observable)invocation.getTargetObject();
		      Field fld = invocation.getField();
		      String fieldName = fld.getName();
		      fld.setAccessible(true);
		      Object oldVal = invocation.getField().get(target);
		      Object result = invocation.invokeNext();
		      Object newVal = invocation.getField().get(target);
		      
		      target.notifyObservers("Changed " + fieldName + " from " + oldVal + " to " + newVal);

		      return result;
		} finally {
			
		}
	}

}
